package cn.caidabao.gb.component.sip.server.request.send;

import cn.caidabao.gb.bean.GBSipRegisterSession;
import cn.caidabao.gb.bean.OGSipCallIdCallBack;
import cn.caidabao.gb.bean.QueryObject;
import cn.caidabao.gb.component.sip.CustomSipServer;
import cn.caidabao.gb.component.sip.server.storage.CallBackStorage;
import cn.caidabao.gb.util.CallBackIdUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Slf4j
@Component
public class QueryMessageSender extends RequestSender<QueryObject,Object>{
    @Resource
    private CallBackStorage callBackStorage;

    @Override
    public OGSipCallIdCallBack<Object> sendAsync(GBSipRegisterSession gbSipRegisterSession, QueryObject extraData) {
        String sipCallId = CustomSipServer.server.sendMessage(gbSipRegisterSession, extraData);
        String sn = extraData.getSn();
        String deviceId = extraData.getDeviceId();
        String messageCallBackKey = extraData.getCallBackId();
        log.warn("查询设备{}，请求callId{}",deviceId,sipCallId);
        OGSipCallIdCallBack<Object> callBack = new OGSipCallIdCallBack<>(messageCallBackKey);
        callBackStorage.putCallBack(messageCallBackKey,callBack);
        return callBack;
    }
}
